﻿namespace ExamV5.WAPPage
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmStudyCenter : Page
    {
        protected Button butClear;
        protected Button butDefault;
        protected DropDownList DDLDiff;
        protected DropDownList DDLRubricType;
        protected DropDownList DDLStudyType;
        protected DropDownList DDLSubject;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected ImageButton ImgButExit;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected TextBox txtUserCode;
        protected TextBox txtUserName;
        protected UpdatePanel UPPart;

        protected void butClear_Click(object sender, EventArgs e)
        {
            this.publicFun_0.ExecuteSql("delete from StudyHistory  where UserCode='" + this.httpCookie_0.Value + "' and SubjectID=" + this.DDLSubject.SelectedItem.Value);
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckB", "alert('清除练习记录操作成功！')", true);
        }

        protected void butDefault_Click(object sender, EventArgs e)
        {
            if (this.txtUserCode.Text.Trim() != "")
            {
                if (this.DDLSubject.SelectedItem.Value != "0")
                {
                    if (this.DDLRubricType.SelectedIndex >= 0)
                    {
                        string strSql = "select Count(*) as CountInfo from RubricInfo where SubjectID='" + this.DDLSubject.SelectedItem.Value + "' and Flag='B' and RubricType='" + this.DDLRubricType.SelectedItem.Value + "'";
                        if (this.DDLDiff.SelectedItem.Value.Trim() != "Z")
                        {
                            strSql = strSql + " and Difficulty='" + this.DDLDiff.SelectedItem.Value.Trim() + "' ";
                        }
                        string values = this.publicFun_0.GetValues(strSql, "CountInfo");
                        if (!(values.Trim() == "") ? !(values.Trim() == "0") : false)
                        {
                            string str = base.Request.Url.ToString();
                            str = str.Substring(0, str.LastIndexOf('/') + 1);
                            base.Response.Redirect(str + "FrmOnlineStuyCenter.aspx?SubjectName=" + base.Server.UrlEncode(this.DDLSubject.SelectedItem.Text) + "&SubjectID=" + this.DDLSubject.SelectedItem.Value + "&RubricType=" + this.DDLRubricType.SelectedItem.Value + "&RubricDiff=" + this.DDLDiff.SelectedItem.Value + "&StudyType=" + this.DDLStudyType.SelectedItem.Value);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckC", "alert('练习题库中暂没有试题，无法练习,请注意您的选择条件！')", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckE", "alert('请选择练习题型！')", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckE", "alert('请选择练习科目信息！')", true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckD", "alert('请登陆系统才可以练习！')", true);
            }
        }

        protected void DDLSubject_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DDLRubricType.Items.Clear();
            this.DDLRubricType.DataTextField = "RubricType";
            this.DDLRubricType.DataValueField = "RubricType";
            this.DDLRubricType.DataSource = this.publicFun_0.RetrunDataView("select  DISTINCT RubricType  from RubricInfo where SubjectID='" + this.DDLSubject.SelectedItem.Value + "' and Flag='B' and RubricType<>'I'  order by RubricType");
            this.DDLRubricType.DataBind();
            if (this.DDLRubricType.Items.Count != 0)
            {
                for (int i = 0; i < this.DDLRubricType.Items.Count; i++)
                {
                    this.DDLRubricType.Items[i].Text = this.publicFun_0.GetRubricType(this.DDLRubricType.Items[i].Value, "0");
                }
            }
            else
            {
                ListItem item = new ListItem("", "0");
                this.DDLRubricType.Items.Add(item);
            }
            this.butClear.Visible = true;
        }

        protected void ImgButExit_Click(object sender, ImageClickEventArgs e)
        {
            base.Response.Cookies["ExamUserCode"].Value = "";
            base.Response.Cookies["ExamUserName"].Value = "";
            base.Response.Cookies["ExamDeptName"].Value = "";
            base.Response.Cookies["ExamDeptID"].Value = "";
            base.Response.Cookies["ExamWorker"].Value = "";
            base.Response.Cookies["ExamUserSex"].Value = "";
            base.Response.Cookies["ExamUserLevel"].Value = "";
            base.Response.Cookies["ExamUserGWName"].Value = "";
            base.Response.Cookies["ExamUserGWLevel"].Value = "";
            string str = base.Request.Url.ToString();
            str = str.Substring(0, str.LastIndexOf('/') + 1);
            base.Response.Redirect(str + "FrmLogin.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) != 0x3a)
                {
                    if (!base.IsPostBack)
                    {
                        this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "在线练习";
                        this.butClear.Visible = false;
                        this.butClear.Attributes.Add("onclick", "javascript:{if(confirm('确定要清除此科目下的所有练习记录吗？')==false) return false;}");
                        if (this.publicFun_0.ReturnPaperData() != "Yes")
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                        }
                        else
                        {
                            this.txtUserCode.Text = this.httpCookie_0.Value;
                            this.txtUserName.Text = this.httpCookie_1.Value;
                            this.DDLRubricType.Items.Clear();
                            this.publicFun_0.LoadSubjectInfo(this.DDLSubject, this.httpCookie_0.Value, "N", "B", this.httpCookie_3.Value);
                            this.DDLSubject.Items.Insert(0, new ListItem("--请选择练习科目--", "0"));
                            try
                            {
                                this.DDLRubricType.Items.Clear();
                                this.DDLRubricType.DataTextField = "RubricType";
                                this.DDLRubricType.DataValueField = "RubricType";
                                this.DDLRubricType.DataSource = this.publicFun_0.RetrunDataView("select  DISTINCT RubricType  from RubricInfo where SubjectID='" + this.DDLSubject.SelectedItem.Value + "' and Flag='B' and RubricType<>'I'  order by RubricType");
                                this.DDLRubricType.DataBind();
                                if (this.DDLRubricType.Items.Count == 0)
                                {
                                    ListItem item = new ListItem("", "0");
                                    this.DDLRubricType.Items.Add(item);
                                }
                                else
                                {
                                    for (int i = 0; i < this.DDLRubricType.Items.Count; i++)
                                    {
                                        this.DDLRubricType.Items[i].Text = this.publicFun_0.GetRubricType(this.DDLRubricType.Items[i].Value, "0");
                                    }
                                }
                                this.butClear.Visible = true;
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTHB", "alert('该版本为特惠版，此功能未开放！')", true);
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

